package com.qf.card.service.impl;
import com.qf.transfer.dao.TDealParticularsMapper;
import com.qf.transfer.pojo.TDealParticulars;
import com.qf.transfer.service.TDealParticularsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/****
 * @Author:shenkunlin
 * @Description:TDealParticulars业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class TDealParticularsServiceImpl implements TDealParticularsService {

    @Autowired
    private TDealParticularsMapper tDealParticularsMapper;


    /**
     * TDealParticulars条件+分页查询
     * @param tDealParticulars 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<TDealParticulars> findPage(TDealParticulars tDealParticulars, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(tDealParticulars);
        //执行搜索
        return new PageInfo<TDealParticulars>(tDealParticularsMapper.selectByExample(example));
    }

    /**
     * TDealParticulars分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<TDealParticulars> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<TDealParticulars>(tDealParticularsMapper.selectAll());
    }

    /**
     * TDealParticulars条件查询
     * @param tDealParticulars
     * @return
     */
    @Override
    public List<TDealParticulars> findList(TDealParticulars tDealParticulars){
        //构建查询条件
        Example example = createExample(tDealParticulars);
        //根据构建的条件查询数据
        return tDealParticularsMapper.selectByExample(example);
    }


    /**
     * TDealParticulars构建查询对象
     * @param tDealParticulars
     * @return
     */
    public Example createExample(TDealParticulars tDealParticulars){
        Example example=new Example(TDealParticulars.class);
        Example.Criteria criteria = example.createCriteria();
        if(tDealParticulars!=null){
            // 明细详情表id
            if(!StringUtils.isEmpty(tDealParticulars.getPkPId())){
                    criteria.andEqualTo("pkPId",tDealParticulars.getPkPId());
            }
            // 收款人的姓名
            if(!StringUtils.isEmpty(tDealParticulars.getPayeeName())){
                    criteria.andEqualTo("payeeName",tDealParticulars.getPayeeName());
            }
            // 收款人的账号
            if(!StringUtils.isEmpty(tDealParticulars.getPayeeAccount())){
                    criteria.andEqualTo("payeeAccount",tDealParticulars.getPayeeAccount());
            }
            // 支款人的姓名
            if(!StringUtils.isEmpty(tDealParticulars.getPayerName())){
                    criteria.andEqualTo("payerName",tDealParticulars.getPayerName());
            }
            // 支款人的账号
            if(!StringUtils.isEmpty(tDealParticulars.getPayerAccount())){
                    criteria.andEqualTo("payerAccount",tDealParticulars.getPayerAccount());
            }
            // 币种
            if(!StringUtils.isEmpty(tDealParticulars.getCurrency())){
                    criteria.andEqualTo("currency",tDealParticulars.getCurrency());
            }
            // 交易状态
            if(!StringUtils.isEmpty(tDealParticulars.getTrading())){
                    criteria.andEqualTo("trading",tDealParticulars.getTrading());
            }
            // 交易渠道
            if(!StringUtils.isEmpty(tDealParticulars.getTransaction())){
                    criteria.andEqualTo("transaction",tDealParticulars.getTransaction());
            }
            // 交易备注
            if(!StringUtils.isEmpty(tDealParticulars.getComment())){
                    criteria.andEqualTo("comment",tDealParticulars.getComment());
            }
            // 交易金额
            if(!StringUtils.isEmpty(tDealParticulars.getTradingAmount())){
                    criteria.andEqualTo("tradingAmount",tDealParticulars.getTradingAmount());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id){
        tDealParticularsMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改TDealParticulars
     * @param tDealParticulars
     */
    @Override
    public void update(TDealParticulars tDealParticulars){
        tDealParticularsMapper.updateByPrimaryKey(tDealParticulars);
    }

    /**
     * 增加TDealParticulars
     * @param tDealParticulars
     */
    @Override
    public void add(TDealParticulars tDealParticulars){
        tDealParticularsMapper.insert(tDealParticulars);
    }

    /**
     * 根据ID查询TDealParticulars
     * @param id
     * @return
     */
    @Override
    public TDealParticulars findById(Integer id){
        return  tDealParticularsMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询TDealParticulars全部数据
     * @return
     */
    @Override
    public List<TDealParticulars> findAll() {
        return tDealParticularsMapper.selectAll();
    }
}
